from plot_type import *
from border import Fence
from link import Link, Door
from item import TakeableItem, Bed
from inventory_item import Seeds
from building import Building
from map import Map, Blank
from field import Field
from person import SeedSeller

# When placing doors, make sure they are slightly offset from the building they're on
# Otherwise the unwalkability of the building will prevent the player from using the door
class World:    
    def __init__(self):
        self.fields = {}
        
        def create_farm():
            m = Map(1040, 720, 'grass')
            m.set_ground((0,160), 1040, 40, 'path')
            
            m.add_item(Field(24,12), (40, 200))
            m.add_item(Building(320, 80), (240, 0))
            m.add_item(Door('home', (200, 320)), (360,41))
            m.add_item(Link('town', (1040, 160)), (0, 160))
            
            return m
        
        def create_home():
            m = Map(360, 400, 'floor')
            
            m.add_item(Bed(), (0,0))
            m.add_item(Blank(200, 40), (0, 360))
            m.add_item(Blank(120, 40), (240, 360))
            m.add_item(Door('farm', (360, 80)), (200, 360))
            
            return m
        
        def create_town():
            m = Map(1120, 480, 'path')
            m.set_ground((0, 120), 1120, 40, 'grass')
            m.set_ground((0, 200), 1120, 40, 'grass')
            
            m.add_item(Building(320, 80), (760, 0))
            m.add_item(Door('seed_shop', (160, 320)), (840, 41))
            m.add_item(Link('farm', (40, 160)), (1080, 160))
            
            return m
            '''
            f = Field(28, 12, PATH)
            
            # add links
            f.add_content(27, 4, Link('farm', (1, 4)))
            f.add_content(21, 1, Door('seedshop', (4,8)))
            
            #add seed shop
            f.add_content(19, 0, Building('left'))
            f.add_content(19, 1, Building('left'))
            f.add_content(26, 0, Building('right'))
            f.add_content(26, 1, Building('right'))
            for i in range(20, 26):
                for j in range(2):
                    if not i == 21 or not j == 1:
                        f.add_content(i, j, Building('centre'))    

            # add fence
            for i in range(0,20) + range(23,28):
                f.add_content(i, 3, Fence())
            for i in range(28):
                f.add_content(i, 5, Fence())
                
            return f
            '''
        
        def create_seed_shop():
            m = Map(360, 400, 'floor')
            
            m.add_item(SeedSeller(), (160,0))
            m.add_item(Blank(200, 40), (0, 360))
            m.add_item(Blank(120, 40), (240, 360))
            m.add_item(Door('town', (840, 80)), (200, 360))
            
            return m
        
        self.fields['farm'] = create_farm()
        self.fields['home'] = create_home()
        self.fields['town'] = create_town()
        self.fields['seed_shop'] = create_seed_shop()
    
    def get(self, name):
        return self.fields[name]